package com.lemon.blog.system.controller;

import com.lemon.blog.system.domain.BlLink;
import com.lemon.blog.system.service.IBlLinkService;
import com.lemon.common.core.utils.poi.ExcelUtil;
import com.lemon.common.core.web.controller.BaseController;
import com.lemon.common.core.web.domain.AjaxResult;
import com.lemon.common.core.web.page.TableDataInfo;
import com.lemon.common.log.annotation.Log;
import com.lemon.common.log.enums.BusinessType;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import com.lemon.common.security.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 包名称：com.lemon.blog.controller
 * 类名称：BlLinkController
 * 类描述：友情链接Controller
 * 创建人：@author huangpeng
 * 创建时间：2022-05-04
 */
@Api("友情链接管理")
@RestController
@RequestMapping("/link")
public class BlLinkController extends BaseController
{
    @Autowired
    private IBlLinkService blLinkService;

    /**
     * 查询友情链接列表
     * @Title: list
     * @Description: 查询友情链接列表
     * @param blLink 友情链接
     * @return: TableDataInfo
     * @throws:
     * @author: huangpeng
     * @Date: 2022-05-04
     */
    @RequiresPermissions("blog:link:list")
    @GetMapping("/list")
    public TableDataInfo list(BlLink blLink) {
        startPage();
        List<BlLink> list = blLinkService.selectBlLinkList(blLink);
        return getDataTable(list);
    }

    /**
     * 导出友情链接列表
     * @Title: export
     * @Description: 导出友情链接列表
     * @param response response
     * @param blLink 友情链接
     * @return:
     * @throws:
     * @author: huangpeng
     * @Date: 2022-05-04
     */
    @RequiresPermissions("blog:link:export")
    @Log(title = "友情链接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlLink blLink) {
        List<BlLink> list = blLinkService.selectBlLinkList(blLink);
        ExcelUtil<BlLink> util = new ExcelUtil<BlLink>(BlLink.class);
        util.exportExcel(response, list, "友情链接数据");
    }

    /**
     * 获取友情链接详细信息
     * @Title: getInfo
     * @Description: 获取友情链接详细信息
     * @param linkId 友情链接主键
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022-05-04
     */
    @RequiresPermissions("blog:link:query")
    @GetMapping(value = "/{linkId}")
    public AjaxResult getInfo(@PathVariable("linkId") Long linkId) {
        return AjaxResult.success(blLinkService.selectByPrimaryKey(linkId));
    }

    /**
     * 新增友情链接
     * @Title: add
     * @Description: 新增友情链接
     * @param blLink 友情链接
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022-05-04
     */
    @RequiresPermissions("blog:link:add")
    @Log(title = "友情链接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlLink blLink)
    {
        return toAjax(blLinkService.insert(blLink));
    }

    /**
     * 修改友情链接
     * @Title: edit
     * @Description: 修改友情链接
     * @param blLink 友情链接
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022-05-04
     */
    @RequiresPermissions("blog:link:edit")
    @Log(title = "友情链接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlLink blLink)
    {
        return toAjax(blLinkService.update(blLink));
    }

    /**
     * 删除友情链接
     * @Title: remove
     * @Description: 删除友情链接
     * @param linkIds 需要删除的友情链接主键集合
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022-05-04
     */
    @RequiresPermissions("blog:link:remove")
    @Log(title = "友情链接", businessType = BusinessType.DELETE)
	@DeleteMapping("/{linkIds}")
    public AjaxResult remove(@PathVariable Long[] linkIds) {
        return toAjax(blLinkService.deleteByBatch(linkIds));
    }
}
